<template>
	<!--物资列表-详情列表-修改出库库弹窗-表单-->
	<a-spin :spinning="confirmLoading">
		<j-form-container>
			<a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
				<a-row>
					<a-col :span="12">
						<a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol"
							:label="model.type == '1'?'入库时间':model.type == '2'?'出库时间':model.type == '3'?'录入时间':''"
							prop="createTime" style="margin-bottom: 10px;">
							<j-date showTime :disabled="disabled" :disabled-date="disabledDate"
								:disabled-time="disabledDateTime" date-format="YYYY-MM-DD HH:mm"
								v-model="model.createTime" style="width: 100%;" />
						</a-form-model-item>
					</a-col>

					<a-col :span="12">
						<a-form-model-item
							:label="model.type == '1'?'送货单号':model.type == '2'?'领料单号':model.type == '3'?'单号':''"
							:labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderNo" style="margin-bottom: 10px;">
							<a-input :disabled="disabled" v-model="model.orderNo"
								:placeholder="model.type == '1'?'请输入送货单号':model.type == '2'?'请输入领料单号':model.type == '3'?'请输入单号':''"></a-input>
						</a-form-model-item>
					</a-col>

					<a-col :span="12" v-if="model.type == '1' || model.type == '2' || model.type == '3'">
						<a-form-model-item label="项目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectName"
							style="margin-bottom: 10px;">
							<a-select :disabled="pageType === 'add'?false:true" placeholder="请选择项目"
								:value="model.projectName" @change="handleChange('project',$event)">
								<a-select-option v-for="(item,index) in projectList" :key="index" :value="item">
									{{item.label}}
								</a-select-option>
							</a-select>
						</a-form-model-item>
					</a-col>

					<a-col :span="12" v-if="model.type == '3'">
						<a-form-model-item label="开盘时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="openingTime"
							style="margin-bottom: 10px;">
							<j-date showTime :disabled="disabled"
								:disabled-time="disabledDateTime" date-format="YYYY-MM-DD" v-model="model.openingTime"
								style="width: 100%;" />
						</a-form-model-item>
					</a-col>

					<a-col :span="12" v-if="model.type == '1' || model.type == '2'">
						<a-form-model-item label="仓库" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="warehouseName"
							style="margin-bottom: 10px;">
							<a-select :disabled="pageType === 'add'?false:true || model.projectId ===''"
								placeholder="请选择仓库" :value="model.warehouseName"
								@change="handleChange('warehouse',$event)">
								<a-select-option v-for="(item,index) in warehouseList" :key="index" :value="item">
									{{item.label}}
								</a-select-option>
							</a-select>
						</a-form-model-item>
					</a-col>

					<a-col :span="16">
						<a-form-model-item label="选择分类" :labelCol="labelCol3" :wrapperCol="wrapperCol3"
							prop="categoryOneName" style="margin-bottom: 10px;margin-left: 16px;">
							<a-select :value="model.categoryOneName" :disabled="model.type == '3'?true:false" placeholder="请选择一级分类名称"
								style="width: 140px;margin-right: 10px;" @change="handleChange('categoryOne',$event)">
								<a-select-option v-for="(item,index) in levelOneOptions" :key="index" :value="item">
									{{ item.name }}
								</a-select-option>
							</a-select>
							<a-select :value="model.categoryTwoName" style="width: 140px;margin-right: 10px;"
								:disabled="model.type == '3'?true: model.categoryOneId == ''?true:false" placeholder="请选择二级分类名称"
								@change="handleChange('categoryTwo',$event)">
								<a-select-option v-for="(item,index) in levelTwoOptions" :key="index" :value="item">
									{{ item.name }}
								</a-select-option>
							</a-select>
							<a-select :value="model.categoryThreeName" style="width: 140px"
								:disabled="model.type == '3'?true: model.categoryTwoId == ''?true:false" placeholder="请选择三级分类名称"
								@change="handleChange('categoryThree',$event)">
								<a-select-option v-for="(item,index) in levelThreeOptions" :key="index" :value="item">
									{{ item.name }}
								</a-select-option>
							</a-select>
						</a-form-model-item>
					</a-col>

					<a-col :span="8">
						<a-form-model-item label="物资名称" :labelCol="labelCol4" :wrapperCol="wrapperCol4"
							prop="platformProductName" style="margin-bottom: 10px;">
							<a-select :value="model.platformProductName"
								:disabled="model.type == '3'?true: platformProductList.length === 0?true:false"
								:placeholder="platformProductList.length === 0?'无数据':'请选择物资名称'"
								@change="handleChange('platformProduct',$event)">
								<a-select-option v-for="(item,index) in platformProductList" :key="index" :value="item">
									{{ item.name }}
								</a-select-option>
							</a-select>
						</a-form-model-item>
					</a-col>

					<template v-if="model.type == '1' || model.type == '2' || model.type == '3'">
						<template v-if="model.type == '1' || model.type == '3'">
							<a-col :span="12" v-if="model.type == '1' || model.type == '3'">
								<a-form-model-item label="是否为甲供" :labelCol="labelCol" :wrapperCol="wrapperCol"
									prop="supplierId" style="margin-bottom: 10px;">
									<a-radio-group @change="handleChange('isSupplyA',$event)" :value="model.isSupplyA"
										style="margin-left: 20px;">
										<a-radio :value="0">否</a-radio>
										<a-radio :value="1">是</a-radio>
									</a-radio-group>
								</a-form-model-item>
							</a-col>

							<a-col :span="12">
								<a-form-model-item label="供应商" :labelCol="labelCol" :wrapperCol="wrapperCol"
									prop="supplierName" style="margin-bottom: 10px;">
									<!-- <a-select :disabled="disabled" :options="supplierList" v-model="model.supplierId"
                    placeholder="请输入供应商"></a-select> -->
									<a-select :disabled="disabled" placeholder="请输入供应商" :value="model.supplierName"
										@change="handleChange('supplier',$event)">
										<a-select-option v-for="(item,index) in supplierList" :key="index"
											:value="item">
											{{item.label}}
										</a-select-option>
									</a-select>
								</a-form-model-item>
							</a-col>
						</template>

						<template v-if="model.type == '2'">
							<a-col :span="12">
								<a-form-model-item label="品牌" :labelCol="labelCol" :wrapperCol="wrapperCol"
									prop="brandName" style="margin-bottom: 10px;">
									<a-select :disabled="disabled" placeholder="请选择品牌" :value="model.brandName"
										@change="handleChange('brand',$event)">
										<a-select-option v-for="(item,index) in brandList" :key="index" :value="item">
											{{item.label}}
										</a-select-option>
									</a-select>
								</a-form-model-item>
							</a-col>
						</template>


						<a-col :span="12" style="position: relative;">
							<span v-if="pageType === 'add' || pageType === 'edit'"
								style="font-size:12px;color: red;margin-left: 50px;top:-14px;position: absolute;">
								(如若型号要修改,请先点击其他物资名称,再点击要修改型号的物资名称)</span>
							<a-form-model-item label="型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="model"
								style="margin-bottom: 10px;">
								<a-select :disabled="disabled || (modelList.length === 0)" placeholder="请选择型号"
									:value="model.model" @change="handleChange('model',$event)">
									<a-select-option v-for="(item,index) in modelList" :key="index" :value="item">
										{{item.label}}
									</a-select-option>
								</a-select>
							</a-form-model-item>
						</a-col>
						<a-col :span="12">
							<a-form-model-item label="数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="number"
								style="margin-bottom: 10px;">
								<div style="display: flex;align-items: center;justify-content: space-between;">
									<a-input :disabled="disabled" v-model="model.number" placeholder="请输入数量"
										style="width: calc(100% - 60px);"></a-input>
									<div style="width: 60px;text-align: center;">{{model.unit}}</div>
								</div>
							</a-form-model-item>
						</a-col>
						<a-col :span="12">
							<a-form-model-item label="抽检磅单" :labelCol="labelCol" :wrapperCol="wrapperCol"
								prop="poundNum" style="margin-bottom: 10px;">
								<a-input :disabled="disabled" v-model="model.poundNum" placeholder="请输入抽检磅单"></a-input>
							</a-form-model-item>
						</a-col>
						<a-col :span="12">
							<a-form-model-item label="单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="unit"
								style="margin-bottom: 10px;">
								<a-input :disabled="true" v-model="model.unit" placeholder="请输入单位"></a-input>
							</a-form-model-item>
						</a-col>
						<template v-if="model.type == '2' || model.type == '3'">
							<a-col :span="12">
								<a-form-model-item :label="model.type == '2'?'领料人':model.type == '3'?'领料人/班组':''"
									:labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialHandler"
									style="margin-bottom: 10px;">
									<a-input :disabled="disabled" v-model="model.materialHandler"
										:placeholder="model.type == '2'?'请输入领料人':model.type == '3'?'请输入领料人/班组':''"></a-input>
								</a-form-model-item>
							</a-col>
							<a-col :span="12" v-if="model.type == '2'">
								<a-form-model-item label="领料班组" :labelCol="labelCol" :wrapperCol="wrapperCol"
									prop="materialHandlerGroup" style="margin-bottom: 10px;">
									<a-input :disabled="disabled" v-model="model.materialHandlerGroup"
										placeholder="请输入领料班组"></a-input>
								</a-form-model-item>
							</a-col>
							<a-col :span="12">
								<a-form-model-item :label="model.type == '2'?'用途':model.type == '3'?'用途/使用部位':''"
									:labelCol="labelCol" :wrapperCol="wrapperCol" prop="purpose"
									style="margin-bottom: 10px;">
									<a-input :disabled="disabled" v-model="model.purpose"
										:placeholder="model.type == '2'?'请输入用途':model.type == '3'?'请输入用途/使用部位':''"></a-input>
								</a-form-model-item>
							</a-col>
						</template>

						<template v-if="model.type == '1' || model.type == '3'">
							<a-col :span="12">
								<a-form-model-item label="单价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="price"
									style="margin-bottom: 10px;">
									<div style="display: flex;align-items: center;justify-content: space-between;">
										<a-input :disabled="disabled" v-model="model.price"
											placeholder="请输入单价"></a-input>
										<div style="width: 30px;text-align: center;">元</div>
									</div>
								</a-form-model-item>
							</a-col>
						</template>
						<template v-if="model.type == '1' || model.type == '2'">
							<a-col :span="12" v-if="model.type == '1'">
								<a-form-model-item label="存放方式" :labelCol="labelCol" :wrapperCol="wrapperCol"
									prop="locationModeName" style="margin-bottom: 10px;">
									<a-select :disabled="disabled" placeholder="请选择存放方式" :value="model.locationModeName"
										@change="handleChange('locationMode',$event)">
										<a-select-option v-for="(item,index) in locationModeList" :key="index"
											:value="item">
											{{item.label}}
										</a-select-option>
									</a-select>
								</a-form-model-item>
							</a-col>
							<a-col :span="12">
								<a-form-model-item label="性质" :labelCol="labelCol" :wrapperCol="wrapperCol"
									prop="natureName" style="margin-bottom: 10px;">
									<a-select :disabled="disabled" placeholder="请选择性质" :value="model.natureName"
										@change="handleChange('nature',$event)">
										<a-select-option v-for="(item,index) in natureList" :key="index" :value="item">
											{{item.label}}
										</a-select-option>
									</a-select>
								</a-form-model-item>
							</a-col>
						</template>
					</template>
				</a-row>
				<a-row>
					<a-col :span="24">
						<a-form-model-item label="备注" :labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="remark"
							style="margin-bottom: 10px;">
							<div style="position: relative;">
								<textarea :disabled="disabled" v-model="model.remark" cols="100" rows="3"
									style="width: 95%;padding-right: 30px;line-height: 25px;" maxlength="500"
									:placeholder="disabled?'':'请输入备注'"></textarea>
								<div style="position: absolute;right: 64px;bottom: 20px;font-size: 12px;"
									v-if="model.remark">
									{{model.remark.length}}/500
								</div>
							</div>
						</a-form-model-item>
					</a-col>
				</a-row>
				<a-row>
					<a-col :span="24">
						<a-form-model-item :label="pageType === 'detail'?'送料单/领料单照片':pageType === 'edit'?'上传资料':''"
							:labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="imgUrl" style="margin-bottom: 10px;">
							<div style="display: flex;" v-if="pageType === 'detail'">
								<span v-if="!model.imgUrl" style="font-size: 12px; font-style: italic">无图片</span>
								<imgs-preview v-else :imgs="model.imgUrl" imgH="100px"></imgs-preview>
							</div>
							<div style="display: flex;" v-else-if="pageType === 'edit'">
								<j-upload v-model="model.imgUrl" fileType="image" :disabled="disabled"
									:buttonVisible="!disabled" text="上传图片"></j-upload>
							</div>
						</a-form-model-item>
					</a-col>
				</a-row>
			</a-form-model>
		</j-form-container>
	</a-spin>
</template>

<script>
	import moment from 'moment';
	import JDate from '@/components/jeecg/JDate'
	import {
		httpAction,
		getAction,
		postAction
	} from '@/api/manage'
	export default {
		name: 'WtMaterialsForm',
		components: {
			JDate,
		},
		data() {
			return {
				id: '',
				confirmLoading: false,
				labelCol: {
					xs: {
						span: 24
					},
					sm: {
						span: 6
					},
				},
				wrapperCol: {
					xs: {
						span: 24
					},
					sm: {
						span: 16
					},
				},
				labelCol2: {
					xs: {
						span: 24
					},
					sm: {
						span: 3
					},
				},
				wrapperCol2: {
					xs: {
						span: 24
					},
					sm: {
						span: 21
					},
				},
				labelCol3: {
					xs: {
						span: 24
					},
					sm: {
						span: 4
					},
				},
				wrapperCol3: {
					xs: {
						span: 24
					},
					sm: {
						span: 20
					},
				},
				labelCol4: {
					xs: {
						span: 24
					},
					sm: {
						span: 6
					},
				},
				wrapperCol4: {
					xs: {
						span: 24
					},
					sm: {
						span: 15
					},
				},
				model: {
					id: '',
					orderNo: '',
					createTime: '',
					openingTime: '',
					projectName: '',
					projectId: '',
					warehouseName: '',
					warehouseId: '',
					supplierName: '',
					supplierId: '',
					isSupplyA: 0,
					platformProductName: '',
					platformProductId: '',
					model: '',
					number: '',
					poundNum: '',
					price: '',
					locationMode: '',
					locationModeName: '',
					unit: '',
					nature: '',
					natureName: '',
					remark: '',
					imgUrl: '',
					//出库单
					brandName: '',
					brandId: '',
					materialHandler: '',
					materialHandlerGroup: '',
					purpose: '',
				},

				levelOneOptions: [], //一级分类列表
				levelTwoOptions: [], //二级分类列表
				levelThreeOptions: [], //三级分类列表
				projectList: [], //项目列表
				supplierList: [], //经销商列表
				platformProductList: [], //物资列表
				warehouseList: [], //仓库列表
				brandList: [], //品牌列表
				locationModeList: [{
					value: 1,
					label: '露天'
				}, {
					value: 2,
					label: '遮蔽'
				}, {
					value: 3,
					label: '室内'
				}, {
					value: 4,
					label: '顶棚'
				}], //存放方式列表
				natureList: [], //性质列表
				range: [{
					"value": 1,
					"text": "是"
				}, {
					"value": 0,
					"text": "否"
				}],
				modelList: [], //型号列表
				validatorRules: {},
				url: {
					list: '',
					edit: '/materials/wtMaterials/updateEntrance',
					edit2:'/materials/wtMaterials/updateDelivery',
					edit3:'/materials/wtMaterials/updateIngressEgress',
					queryById: '',
					wtMaterialsDetail: {
						list: '',
					},
				},
			}
		},
		isorter: {
			column: 'createTime',
			order: 'desc',
		},

		props: {
			//表单禁用
			disabled: {
				type: Boolean,
				default: false,
				required: false,
			},
			pageType: {
				type: String,
				default: '',
			},
			id: {
				type: String,
			},
		},
		computed: {},
		created() {
			if (this.pageType === 'add') {
				this.Dictionary();
			}
		},
		mounted() {
			window.onbeforeunload = function(e) {
				var storage = window.localStorage
				storage.clear()
			}
		},
		methods: {
			moment,
			range(start, end) {
				const result = [];
				for (let i = start; i < end; i++) {
					result.push(i);
				}
				return result;
			},
			disabledDate(current) {
				return current && current > moment().endOf('day');
			},
			disabledDateTime() {

			},
			handleChange(type, item) {
				console.log(111, type, item)
				if (type === 'project') {
					this.model.projectName = item.label;
					this.model.projectId = item.value;

					//清空联动
					this.model.warehouseName = '';
					this.model.warehouseId = '';
					this.warehouseList = [];
					if (!!this.model.projectId) {
						let params = {
							projectId: this.model.projectId
						}
						//仓库列表
						getAction(`/materials/wtWarehouse/getList`, params).then((res) => {
							if (res.success) {

								let treeList = res.result;
								if (treeList && treeList.length > 0) {
									this.warehouseList = [...treeList].map((v) => ({
										...v,
										value: v.id,
										label: v.name,
									}))
								}
							}
						})
					}
				} else if (type === 'supplier') {
					this.model.supplierName = item.label;
					this.model.supplierId = item.value;
				} else if (type === 'warehouse') {
					this.model.warehouseName = item.label;
					this.model.warehouseId = item.value;
				} else if (type === 'locationMode') {
					this.model.locationModeName = item.label;
					this.model.locationMode = item.value;
				} else if (type === 'platformProduct') {
					this.model.platformProductName = item.label;
					this.model.platformProductId = item.value;

					this.model.unit = item.unit;
					this.modelList = item.model.split(',').map(item => ({
						value: item,
						label: item
					}))
				} else if (type === 'model') {
					this.model.model = item.value;
				} else if (type === 'nature') {
					this.model.natureName = item.label;
					this.model.nature = item.value;
				} else if (type === 'isSupplyA') {
					this.model.isSupplyA = item.target.value;
					this.validatorRules.supplierName = [{
						required: this.model.isSupplyA == 1 ? false:true,
						message: '供应商不能为空,请选择~',
						trigger: 'change'
					}];
				} else if (type === 'brand') {
					this.model.brandName = item.label;
					this.model.brandId = item.value;
				} else if (type === 'categoryOne') { //分类一
					let levelTwoOptions = item.children;
					this.model.categoryOneName = item.name;
					this.model.categoryOneId = item.id;
					//清空联动
					this.model.categoryTwoName = '';
					this.model.categoryTwoId = '';
					this.model.categoryThreeName = '';
					this.model.categoryThreeId = '';
					this.model.platformProductName = '';
					this.model.platformProductId = '';
					this.platformProductList = [];
					this.categoryTwoName = [];
					this.levelThreeOptions = [];
					this.modelList = [];
					this.model.unit = '';
					this.model.model = '';
					this.model.supplierName = '';
					this.model.supplierId = '';
					//this.supplierList = [];
					if (levelTwoOptions && levelTwoOptions.length > 0) {
						this.levelTwoOptions = levelTwoOptions.map((v) => ({
							...v,
							value: v.id,
							label: v.name,
						}))
					}
				} else if (type === 'categoryTwo') { //分类二
					let levelThreeOptions = item.children;
					this.model.categoryTwoName = item.name;
					this.model.categoryTwoId = item.id;
					//清空联动
					this.model.categoryThreeName = '';
					this.model.categoryThreeId = '';
					this.levelThreeOptions = [];
					this.modelList = [];
					this.model.unit = '';
					this.model.model = '';
					this.model.supplierName = '';
					this.model.supplierId = '';
					//this.supplierList = [];
					if (levelThreeOptions && levelThreeOptions.length > 0) {
						this.levelThreeOptions = levelThreeOptions.map((v) => ({
							...v,
							value: v.id,
							label: v.name,
						}))
					} else {
						this.model.platformProductName = '';
						this.model.platformProductId = '';
						this.platformProductList = [];
						this.getList('categoryTwoId', this.model.categoryTwoId);
					}

				} else if (type === 'categoryThree') { //分类三
					this.model.categoryThreeName = item.name;
					this.model.categoryThreeId = item.id;
					this.modelList = [];
					this.model.unit = '';
					this.model.model = '';
					this.model.supplierName = '';
					this.model.supplierId = '';
					this.supplierList = [];
					if (!!this.model.categoryThreeId) {
						this.model.platformProductName = '';
						this.model.platformProductId = '';
						this.platformProductList = [];
						this.getList('categoryThreeId', this.model.categoryThreeId);
					}
				}
				this.$forceUpdate();
			},

			Dictionary() {
				//验证表单
				if (this.pageType === 'add' || this.pageType === 'edit') {
					if (this.model.type == '1') {
						this.validatorRules = {
							createTime: [{
								required: true,
								message: '入库时间不能为空,请选择~',
								trigger: 'change'
							}],
							orderNo: [{
								required: true,
								message: '送货单号不能为空,请输入~',
								trigger: 'blur'
							}],
							projectName: [{
								required: true,
								message: '项目不能为空,请选择~',
								trigger: 'change'
							}],
							warehouseName: [{
								required: true,
								message: '仓库不能为空,请选择~',
								trigger: 'change'
							}],
							supplierName: [{
								required: this.model.isSupplyA == 1 ? false:true,
								message: '供应商不能为空,请选择~',
								trigger: 'change'
							}],
							platformProductName: [{
								required: true,
								message: '物资名称不能为空,请选择~',
								trigger: 'change'
							}],
							model: [{
								required: true,
								message: '型号不能为空,请选择~',
								trigger: 'change'
							}],
							number: [{
								required: true,
								message: '数量不能为空,请输入~',
								trigger: 'blur'
							}],
							locationModeName: [{
								required: true,
								message: '存放方式不能为空,请选择~',
								trigger: 'change'
							}],
							natureName: [{
								required: true,
								message: '性质不能为空,请选择~',
								trigger: 'change'
							}],
							imgUrl: [{
								required: true,
								message: '上传资料不能为空,请上传~',
								trigger: 'change'
							}],
						}
						if (this.pageType === 'add') {
							this.natureList = [{
								value: 1,
								label: "新入"
							}, {
								value: 2,
								label: "借/还"
							}, {
								value: 3,
								label: "租"
							}, {
								value: 4,
								label: "调拨"
							}];
						}
						console.log(111, this.validatorRules)
					} else if (this.model.type == '2') {
						this.validatorRules = {
							createTime: [{
								required: true,
								message: '出库时间不能为空,请选择~',
								trigger: 'change'
							}],
							orderNo: [{
								required: true,
								message: '领料单号不能为空,请输入~',
								trigger: 'blur'
							}],
							projectName: [{
								required: true,
								message: '项目不能为空,请选择~',
								trigger: 'change'
							}],
							warehouseName: [{
								required: true,
								message: '仓库不能为空,请选择~',
								trigger: 'change'
							}],
							platformProductName: [{
								required: true,
								message: '物资名称不能为空,请选择~',
								trigger: 'change'
							}],
							model: [{
								required: true,
								message: '型号不能为空,请选择~',
								trigger: 'change'
							}],
							number: [{
								required: true,
								message: '数量不能为空,请输入~',
								trigger: 'blur'
							}],
							natureName: [{
								required: true,
								message: '性质不能为空,请选择~',
								trigger: 'change'
							}],
							materialHandler: [{
								required: true,
								message: '领料人不能为空,请选择~',
								trigger: 'blur'
							}],
							materialHandlerGroup: [{
								required: true,
								message: '领料班组不能为空,请选择~',
								trigger: 'blur'
							}],
							purpose: [{
								required: true,
								message: '用途不能为空,请选择~',
								trigger: 'blur'
							}],
							imgUrl: [{
								required: true,
								message: '上传资料不能为空,请上传~',
								trigger: 'change'
							}],
						}
						if (this.pageType === 'add') {
							this.natureList = [{
								value: 1,
								label: "领取"
							}, {
								value: 2,
								label: "借/退"
							}, {
								value: 3,
								label: "租还"
							}, {
								value: 4,
								label: "调拨"
							}];
						}
					} else if (this.model.type == '3') {
						this.validatorRules = {
							createTime: [{
								required: true,
								message: '出库时间不能为空,请选择~',
								trigger: 'change'
							}],
							orderNo: [{
								required: true,
								message: '单号不能为空,请输入~',
								trigger: 'blur'
							}],
							projectName: [{
								required: true,
								message: '项目不能为空,请选择~',
								trigger: 'change'
							}],
							supplierName: [{
								required: this.model.isSupplyA == 1 ? false:true,
								message: '供应商不能为空,请选择~',
								trigger: 'change'
							}],
							platformProductName: [{
								required: true,
								message: '物资名称不能为空,请选择~',
								trigger: 'change'
							}],
							model: [{
								required: true,
								message: '型号不能为空,请选择~',
								trigger: 'change'
							}],
							number: [{
								required: true,
								message: '数量不能为空,请输入~',
								trigger: 'blur'
							}],
							materialHandler: [{
								required: true,
								message: '领料人不能为空,请选择~',
								trigger: 'blur'
							}],
							materialHandlerGroup: [{
								required: true,
								message: '领料班组不能为空,请选择~',
								trigger: 'blur'
							}],
							purpose: [{
								required: true,
								message: '用途/使用部位不能为空,请选择~',
								trigger: 'blur'
							}],
							imgUrl: [{
								required: true,
								message: '上传资料不能为空,请上传~',
								trigger: 'change'
							}],
						}
					}
				};
				//获取品牌列表
				getAction(`/wtBrand/getListByCategory`).then((res) => {
					if (res.success) {
						let treeList = []
						treeList = res.result;
						this.brandList = [...treeList].map((v) => ({
							...v,
							value: v.id,
							label: (!!v.name) ? v.name : '未命名'
						}))
					}
				})
				//分类列表
				getAction('/wtCategory/list').then((res) => {
					if (res.success) {
						let treeList = []
						treeList = res.result;
						this.levelOneOptions = [...treeList].map((v) => ({
							...v,
							value: v.id,
							label: v.name,
						}))
						if (this.pageType === 'edit') {
							if (!!this.model.categoryOneId) {
								if (this.levelOneOptions && this.levelOneOptions.length > 0) {
									this.levelOneOptions.forEach(items => {
										if (items.id === this.model.categoryOneId) {
											this.levelTwoOptions = items.children;
										}
									})
									if (!!this.model.categoryTwoId) {
										if (this.levelTwoOptions && this.levelTwoOptions.length > 0) {
											this.levelTwoOptions.forEach(item => {
												if (item.id === this.model.categoryTwoId) {
													this.levelThreeOptions = item.children;
												}
											})
											if (!!this.model.categoryThreeId) {
												if (this.levelThreeOptions && this.levelThreeOptions.length > 0) {
													this.getProductName();
												}
											} else {
												this.getProductName();
											}
										}
									}
								}
							}
						}
					}
				})
				//项目列表
				getAction(`/materials/wtWarehouse/getProjectList`).then((res) => {
					if (res.success) {
						let treeList = []
						treeList = res.result;
						if (treeList && treeList.length > 0) {
							this.projectList = [...treeList].map((v) => ({
								...v,
								value: v.id,
								label: v.departName,
							}))
						}
					}
				})
				if (!!this.model.projectId) {
					let params = {
						projectId: this.model.projectId
					}
					//仓库列表
					getAction(`/materials/wtWarehouse/getList`, params).then((res) => {
						if (res.success) {
							this.warehouseList = [];
							let treeList = res.result;
							if (treeList && treeList.length > 0) {
								this.warehouseList = [...treeList].map((v) => ({
									...v,
									value: v.id,
									label: v.name,
								}))
								if (this.pageType === 'edit') {
									let info = this.warehouseList.find((item) => item.value == this.model
										.warehouseId);
									if (!!info.label) {
										this.model.warehouseName = info.label;
									}
								}
							}
						}
					})
				}

				//供应商列表
				getAction(`/wtSupplier/getListByCategory`).then((res) => {
					if (res.success) {
						let treeList = []
						treeList = res.result;
						if (treeList && treeList.length > 0) {
							this.supplierList = [...treeList].map((v) => ({
								...v,
								value: v.id,
								label: v.name,
							}))
						}
					}
				})

			},
			//获取物资
			getProductName() {
				let params = {
					categoryOneId: this.model.categoryOneId,
					categoryTwoId: this.model.categoryTwoId,
					categoryThreeId: this.model.categoryThreeId,
					name: ''
				}
				//获取物资名称
				getAction('/product/wtPlatformProduct/getListByCategory', params).then((res2) => {
					if (res2.success) {
						let treeList2 = []
						treeList2 = res2.result;
						this.platformProductList = [...treeList2].map((v) => ({
							...v,
							value: v.id,
							label: v.name,
						}))
						if (this.pageType === 'edit') {
							let info = this.platformProductList.find((item) => item.value == this.model
								.platformProductId);
							if (!!info.model) {
								this.modelList = info.model.split(',').map(ite => ({
									value: ite,
									label: ite
								}))
							}
						}
					}
				})
			},
			getList(category, id) {
				let params = {
					categoryOneId: this.model.categoryOneId,
					categoryTwoId: this.model.categoryTwoId,
					categoryThreeId: this.model.categoryThreeId,
					name: ''
				}
				//获取物资名称
				getAction('/product/wtPlatformProduct/getListByCategory', params).then((res) => {
					if (res.success) {
						let treeList = []
						treeList = res.result;
						this.platformProductList = [...treeList].map((v) => ({
							...v,
							value: v.id,
							label: v.name,
						}))
					}
				})
				let params2 = {
					categoryThreeId: this.model.categoryThreeId,
				}
				//供应商列表
				getAction(`/wtSupplier/getListByCategory`, params2).then((res) => {
					if (res.success) {
						let treeList = []
						treeList = res.result;
						if (treeList && treeList.length > 0) {
							this.supplierList = [...treeList].map((v) => {
								return {
									...v,
									value: v.id,
									label: v.name,
								}
							})
						}
					}
				})
			},
			edit(record) {
				console.log(22, record)
				this.model = Object.assign({}, record)
				if (this.pageType === 'edit' || this.pageType === 'detail') {
					if (this.model.type == '1') {
						this.natureList = [{
							value: 1,
							label: "新入"
						}, {
							value: 2,
							label: "借/还"
						}, {
							value: 3,
							label: "租"
						}, {
							value: 4,
							label: "调拨"
						}];
					} else if (this.model.type == '2') {
						this.natureList = [{
							value: 1,
							label: "领取"
						}, {
							value: 2,
							label: "借/退"
						}, {
							value: 3,
							label: "租还"
						}, {
							value: 4,
							label: "调拨"
						}];
					}
					this.model.isSupplyA = parseInt(this.model.isSupplyA);
					let info = this.locationModeList.find((item) => item.value == this.model.locationMode);
					if (!!info) {
						this.model.locationModeName = info.label;
					}
					let info1 = this.natureList.find((item) => item.value == this.model.nature);
					if (!!info1) {
						this.model.natureName = info1.label;
					}
					if (record.type == 3) {
						let params = {
							materialsDetailId: record.id
						}
						//图片列表
						getAction(`/materials/wtMaterialsImgUrl/getListBymaterialsDetailId`, params).then((res) => {
							if (res.success) {
								let imgUrls = []
								let imgUrl = '';
								imgUrls = res.result;
								if (imgUrls && imgUrls.length > 0) {
									imgUrls.forEach(iii => {
										if (!!imgUrl) {
											imgUrl += ',' + iii.imgUrl
										} else {
											imgUrl += iii.imgUrl
										}
									})
								}
								this.model.imgUrl = imgUrl;
								this.$forceUpdate();
							}
						})
					}
				}
				this.Dictionary();
				this.visible = true
				// this.editAfter()
			},
			submitForm() {
				const _self = this
				if (this.pageType === 'add' || this.pageType === 'edit') {
					if (!this.model.createTime) {
						_self.$message.warning(this.model.type == '1' ? '入库时间不能为空,请选择~' : this.model.type == '2' ?
							'出库时间不能为空,请选择~' :
							this.model.type == '3' ? '录入时间不能为空,请选择~' : '');
						return;
					}
					if (!this.model.orderNo) {
						_self.$message.warning(this.model.type == '1' ? '送货单号不能为空,请选择~' : this.model.type == '2' ?
							'领料单号不能为空,请选择~' :
							this.model.type == '3' ? '单号不能为空,请选择~' : '');
						return;
					}
					if (!this.model.projectName) {
						_self.$message.warning('项目不能为空,请选择~');
						return;
					}

					if (this.model.type == '1') {
						if (!this.model.warehouseName) {
							_self.$message.warning('仓库不能为空,请选择~');
							return;
						}
						if (this.model.isSupplyA == 0) {
							if (!this.model.supplierName) {
								_self.$message.warning('供应商不能为空,请选择~');
								return;
							}
						}
						if (!this.model.platformProductName) {
							_self.$message.warning('物资名称不能为空,请选择~');
							return;
						}
						if (!this.model.model) {
							_self.$message.warning('型号不能为空,请选择~');
							return;
						}
						if (!this.model.number) {
							_self.$message.warning('数量不能为空,请输入~');
							return;
						}
						if (!this.model.locationModeName) {
							_self.$message.warning('存放方式不能为空,请选择~');
							return;
						}
						if (!this.model.natureName) {
							_self.$message.warning('性质不能为空,请选择~');
							return;
						}
					} else if (this.model.type == '2') {
						if (!this.model.warehouseName) {
							_self.$message.warning('仓库不能为空,请选择~');
							return;
						}
						if (!this.model.platformProductName) {
							_self.$message.warning('物资名称不能为空,请选择~');
							return;
						}
						if (!this.model.model) {
							_self.$message.warning('型号不能为空,请选择~');
							return;
						}
						if (!this.model.number) {
							_self.$message.warning('数量不能为空,请输入~');
							return;
						}
						if (!this.model.natureName) {
							_self.$message.warning('性质不能为空,请选择~');
							return;
						}
						if (!this.model.materialHandler) {
							_self.$message.warning('领料人不能为空,请选择~');
							return;
						}
						if (!this.model.materialHandlerGroup) {
							_self.$message.warning('领料班组不能为空,请选择~');
							return;
						}
						if (!this.model.purpose) {
							_self.$message.warning('用途不能为空,请选择~');
							return;
						}
					} else if (this.model.type == '3') {
						if (this.model.isSupplyA == 0) {
							if (!this.model.supplierName) {
								_self.$message.warning('供应商不能为空,请选择~');
								return;
							}
						}
						if (!this.model.platformProductName) {
							_self.$message.warning('物资名称不能为空,请选择~');
							return;
						}
						if (!this.model.model) {
							_self.$message.warning('型号不能为空,请选择~');
							return;
						}
						if (!this.model.number) {
							_self.$message.warning('数量不能为空,请输入~');
							return;
						}
						if (!this.model.materialHandler) {
							_self.$message.warning('领料人不能为空,请选择~');
							return;
						}
						if (!this.model.purpose) {
							_self.$message.warning('用途/使用部位不能为空,请选择~');
							return;
						}
					}
					if (!this.model.imgUrl) {
						_self.$message.warning('上传资料不能为空,请上传~');
						return;
					}
				}

				_self.$refs.form.validate((valid) => {
					if (valid) {
						_self.confirmLoading = true
						let httpurl = ''
						if (!!_self.model.id) {
							if(_self.model.type == '3'){
								httpurl = _self.url.edit3;
							}else if(_self.model.type == '2'){
								httpurl = _self.url.edit2;
							}else if(_self.model.type == '1'){
								httpurl = _self.url.edit;
							}
						} else {
							httpurl = _self.url.add
						}
						// console.log('提交接口：', _self.model)
						httpAction(httpurl, _self.model, 'post').then((res) => {
								if (res.success) {
									_self.$message.success(res.message)
									_self.$emit('ok')
								} else {
									_self.$message.warning(res.message)
								}
							})
							.finally(() => {
								_self.confirmLoading = false
							})
					}
				})
			},
		},
	}
</script>

<style scoped>
	.count {
		width: 200px;
		height: 30px;
		/* background-color: #000; */
		margin-top: -40px;
	}

	.col1 {
		display: inline-block;
		width: 300px;
	}

	.col2 {
		display: inline-block;
		width: 55%;
		margin-left: -80px;
		margin-right: -100px;
	}
</style>